//
//  ALLProgressView.m
//  Ginix
//
//  Created by 冯志强 on 2025/3/9.
//

#import "ALLProgressView.h"

@interface ALLProgressView(){
    
   

    
}
@property (nonatomic,strong) UIView * firstLine;
@property (nonatomic,strong) UIView * firstCenterLine;
@property (nonatomic,strong) UILabel * firstLabel;

@property (nonatomic,strong) UIView * secondLine;
@property (nonatomic,strong) UIView * secondCenterLine;
@property (nonatomic,strong) UILabel * secondLabel;

@property (nonatomic,strong) UIView * lastLine;
@property (nonatomic,strong) UIView * lastCenterLine;
@property (nonatomic,strong) UILabel * lastLabel;

@property (nonatomic,strong)  CAShapeLayer *firstLayer;
@property (nonatomic,strong)  CAShapeLayer *lastLayer;


@end

@implementation ALLProgressView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
        [self setupDottedDashedLine];
        [self setupDottedDashedLineLast];
    }
    return self;
}

-(void)setSubViewLayout{
    
    [self addSubview:self.firstLine];
    [self addSubview:self.firstLabel];
    [self.firstLine addSubview:self.firstCenterLine];
    
    [self addSubview:self.secondLine];
    [self addSubview:self.secondLabel];
    [self.secondLine addSubview:self.secondCenterLine];
    
    [self addSubview:self.lastLine];
    [self addSubview:self.lastLabel];
    [self.lastLine addSubview:self.lastCenterLine];
}


-(void)setIndex:(NSInteger)index{
    
    
    if (index == 1) {
        self.firstLayer.strokeColor = RDRGB(0xAD7D62).CGColor;
        self.secondLine.backgroundColor = RDRGBA(0xAD7D62, 0.30);
        self.secondCenterLine.backgroundColor = RDRGB(0xAD7D62);
    }
    if (index == 2) {
        self.firstLayer.strokeColor = RDRGB(0xAD7D62).CGColor;
        self.secondLine.backgroundColor = RDRGBA(0xAD7D62, 0.30);
        self.secondCenterLine.backgroundColor = RDRGB(0xAD7D62);
        
        self.lastLayer.strokeColor = RDRGB(0xAD7D62).CGColor;
        self.lastLine.backgroundColor = RDRGBA(0xAD7D62, 0.30);
        self.lastCenterLine.backgroundColor = RDRGB(0xAD7D62);
    }
    
}

- (void)setupDottedDashedLine {
    // 创建一个 UIBezierPath 对象，这里以水平直线为例
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(GETMaxX(self.firstLine) + 8 * FMScaleX, 8 * FMScaleX)];
    [path addLineToPoint:CGPointMake(GETMinX(self.secondLine) - 5 * FMScaleX, 8 * FMScaleX)];

    // 创建一个 CAShapeLayer 对象
    self.firstLayer = [CAShapeLayer layer];
    self.firstLayer.path = path.CGPath;

    // 设置圆点虚线样式
    // 这里的数组表示：第一个元素是圆点的长度，第二个元素是间隔的长度
    CGFloat dashes[] = {4 , 10};
    self.firstLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:dashes[0]], [NSNumber numberWithInt:dashes[1]], nil];

    // 设置线宽，线宽会影响圆点的大小
    self.firstLayer.lineWidth = 4.0 ;
    // 设置初始线的颜色
    self.firstLayer.strokeColor = RDRGB(0xE2E0DE).CGColor;
    // 填充颜色设为透明
    self.firstLayer.fillColor = [UIColor clearColor].CGColor;
    // 设置端点样式为圆形，这样就能形成圆点效果
    self.firstLayer.lineCap = kCALineCapRound;
    // 将 CAShapeLayer 添加到视图的 layer 上
    [self.layer addSublayer:self.firstLayer];
}

- (void)setupDottedDashedLineLast {
    // 创建一个 UIBezierPath 对象，这里以水平直线为例
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(GETMaxX(self.secondLine) + 10 * FMScaleX, 8 * FMScaleX)];
    [path addLineToPoint:CGPointMake(GETMinX(self.lastLine) - 5 * FMScaleX, 8 * FMScaleX)];

    // 创建一个 CAShapeLayer 对象
    self.lastLayer = [CAShapeLayer layer];
    self.lastLayer.path = path.CGPath;

    // 设置圆点虚线样式
    // 这里的数组表示：第一个元素是圆点的长度，第二个元素是间隔的长度
    CGFloat dashes[] = {4 , 10};
    self.lastLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:dashes[0]], [NSNumber numberWithInt:dashes[1]], nil];

    // 设置线宽，线宽会影响圆点的大小
    self.lastLayer.lineWidth = 4.0 ;
    // 设置初始线的颜色
    self.lastLayer.strokeColor = RDRGB(0xE2E0DE).CGColor;
    // 填充颜色设为透明
    self.lastLayer.fillColor = [UIColor clearColor].CGColor;
    // 设置端点样式为圆形，这样就能形成圆点效果
    self.lastLayer.lineCap = kCALineCapRound;
    // 将 CAShapeLayer 添加到视图的 layer 上
    [self.layer addSublayer:self.lastLayer];
}


-(UIView *)firstLine{
    
    if (!_firstLine) {
        _firstLine = [[UIView alloc]initWithFrame:CGRectMake(20 * FMScaleX, 0 * FMScaleX, 18 * FMScaleX, 18 * FMScaleX)];
        _firstLine.backgroundColor = RDRGBA(0xAD7D62, 0.30);
        [_firstLine setCornerRadius:9 * FMScaleX];
    }
    return _firstLine;
}
-(UIView *)firstCenterLine{
    
    if (!_firstCenterLine) {
        _firstCenterLine = [[UIView alloc]initWithFrame:CGRectMake(4 * FMScaleX, 4 * FMScaleX, 10 * FMScaleX, 10 * FMScaleX)];
        [_firstCenterLine setCornerRadius:5 * FMScaleX];
        _firstCenterLine.backgroundColor = RDRGB(0xAD7D62);
    }
    return _firstCenterLine;
}
-(UILabel *)firstLabel{
    
    if (!_firstLabel) {
        _firstLabel = [[UILabel alloc]initWithFrame:CGRectMake(3 * FMScaleX, GETMaxY(self.firstLine) + 6 * FMScaleX, 60 * FMScaleX, 22 * FMScaleX)];
        _firstLabel.font = Medium(13 * FMScaleX);
        _firstLabel.textColor = RDRGB(0xAD7D62);
        _firstLabel.text = @"左手佩戴";
        _firstLabel.textAlignment = NSTextAlignmentCenter;

    }
    return _firstLabel  ;
}

-(UIView *)secondLine{
    
    if (!_secondLine) {
        _secondLine = [[UIView alloc]initWithFrame:CGRectMake((self.getWidth - 18 * FMScaleX) / 2, 0 * FMScaleX, 18 * FMScaleX, 18 * FMScaleX)];
        _secondLine.backgroundColor = RDRGBA(0xC7BDB2, 0.31);
        [_secondLine setCornerRadius:9 * FMScaleX];
    }
    return _secondLine;
}
-(UIView *)secondCenterLine{
    
    if (!_secondCenterLine) {
        _secondCenterLine = [[UIView alloc]initWithFrame:CGRectMake(4 * FMScaleX, 4 * FMScaleX, 10 * FMScaleX, 10 * FMScaleX)];
        [_secondCenterLine setCornerRadius:5 * FMScaleX];
        _secondCenterLine.backgroundColor = RDRGB(0xC7BEB2);
    }
    return _secondCenterLine;
}
-(UILabel *)secondLabel{
    
    if (!_secondLabel) {
        _secondLabel = [[UILabel alloc]initWithFrame:CGRectMake((self.getWidth - 60 * FMScaleX) / 2, GETMaxY(self.secondLine) + 6 * FMScaleX, 60 * FMScaleX, 22 * FMScaleX)];
        _secondLabel.font = Medium(13 * FMScaleX);
        _secondLabel.textColor = RDRGB(0xAD7D62);
        _secondLabel.text = @"右手佩戴";
        _secondLabel.textAlignment = NSTextAlignmentCenter;

    }
    return _secondLabel  ;
}

-(UIView *)lastLine{
    
    if (!_lastLine) {
        _lastLine = [[UIView alloc]initWithFrame:CGRectMake((self.getWidth - 38 * FMScaleX), 0 * FMScaleX, 18 * FMScaleX, 18 * FMScaleX)];
        _lastLine.backgroundColor = RDRGBA(0xC7BDB2, 0.31);
        [_lastLine setCornerRadius:9 * FMScaleX];
    }
    return _lastLine;
}
-(UIView *)lastCenterLine{
    
    if (!_lastCenterLine) {
        _lastCenterLine = [[UIView alloc]initWithFrame:CGRectMake(4 * FMScaleX, 4 * FMScaleX, 10 * FMScaleX, 10 * FMScaleX)];
        [_lastCenterLine setCornerRadius:5 * FMScaleX];
        _lastCenterLine.backgroundColor = RDRGB(0xC7BEB2);
    }
    return _lastCenterLine;
}
-(UILabel *)lastLabel{
    
    if (!_lastLabel) {
        _lastLabel = [[UILabel alloc]initWithFrame:CGRectMake((self.getWidth - 60 * FMScaleX), GETMaxY(self.lastLine) + 6 * FMScaleX, 60 * FMScaleX, 22 * FMScaleX)];
        _lastLabel.font = Medium(13 * FMScaleX);
        _lastLabel.textColor = RDRGB(0xAD7D62);
        _lastLabel.text = @"舌头拍照";
        _lastLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _lastLabel;
}
@end
